{* $Id$ *}
{include_core file="admin/lib/header.html" title="活动展示"}
<div class="page-header border-bottom clearfix">
  <h2 class="left">活动管理<span>{if $events_info}编辑{else}添加{/if}活动</span></h2>
  <a href="{AnUrl('events/admin')}" class="btn btn-default btn-sm right">&lt;&nbsp;返回活动列表</a>
</div>
<!--start:活动新增-->
<div class="add-form">
  <form class="js_creatForm" action="{AnUrl('events/admin/save')}" method="post" enctype="multipart/form-data">
    <input type="hidden" name="id" value="{$events_info.id}">
    <table class="table" cellpadding="0" cellspacing="0">
      <tr>
        <th><label for="" class="add-f-label">活动标题：</label></th>
        <td>
          <input name="info[title]" style="width:490px;" value="{$events_info.title}" type="text" class="add-f-ipt1 js_title">
          <div class="tips"><span style="line-height: 34px;color: #f00;margin-right: 10px;">*</span>活动标题会显示在相应内容的标题位置，最多输入 <span style="color:red;">30</span> 字，还可输入 <span class="js_titleNum" style="color:red;">30</span> 字</div>
        </td>
      </tr>
      <tr>
        <th><label for="" class="add-f-label">活动链接：</label></th>
        <td>
          <input name="info[link]" style="width:490px;" value="{$events_info.link}" type="text" class="add-f-ipt1 js_link">
          <div class="tips">活动链接可以不填写，如果填写后，将会以链接的内容位主。下面的活动内容将无效！</div>
        </td>
      </tr>
      <tr>
        <th valign="top"><label for="" class="add-f-label">活动封面：</label></th>
        <td class="perUpOuter">
          <div class="clearfix">
            <div class="btn-upload left">
              <a href="javascript:void(0);"><i class="icon-upload"></i>上传封面</a>
              <input class="js_cover js_upFile"  type="file" name="cover">
            </div>
            <span class="tips left">&nbsp;&nbsp;&nbsp;活动封面图比例：720*400</span>
          </div>
          <div class="js_upFileBox">
              {if $events_info.cover}
              <img src="{_image($events_info.cover, 'middle')}">
              {else}
              <!-- <img src="{$smarty.const.SITE_URL}/images/m/default/events_default.jpg" width="360"> -->
              {/if}
          </div>
        </td>
      </tr>
      <tr>
        <th valign="top"><label for="" class="add-f-label">内容库内容：</label></th>
        <td>
          <textarea class="js_content" name="info[content]" id="js_editor" style="width:490px;">{$events_info.content}</textarea>
          <div class="tips">内容库内容会显示在详情页显示</div>
        </td>
      </tr>
      <tr><th>&nbsp;</th><td class="noborder"><button type="submit" class="btn btn-success js_submit">&nbsp;&nbsp;&nbsp;确认&nbsp;&nbsp;&nbsp;</button></td></tr>
    </table>
  </form>
</div>
<!--end:活动新增-->
{load_js file='ueditor1_4_3/ueditor.config.js'}
{load_js file='ueditor1_4_3/ueditor.all.js'}
<script>
var resName = 'events';
function setNum(thisClass, maxNum) {
  var presentNum = $('.'+thisClass).val().length;
  var remainNum  = maxNum - presentNum;
  if (remainNum < 0) {
    $('.'+thisClass).val($('.'+thisClass).val().substr(0,maxNum));
    $('.'+thisClass+'Num').text(0);
  } else {
    $('.'+thisClass+'Num').text(remainNum);
  }
}

var isLink = 0;
$(function(){  
  // 初始化编辑器
  var editor = new UE.ui.Editor({
    serverUrl:"{AnUrl('core/handler/file_uploader?source=ueditor&file_field=Filedata')}",
       initialFrameWidth:600,
       initialFrameHeight:385,
       elementPathEnabled:false,
       autoHeightEnabled: false,
       autoFloatEnabled: false,
       wordCount: false,
       toolbars:[['fullscreen','source', "undo","redo","justifyleft","justifycenter","justifyright","justifyjustify","lineheight","bold","italic","underline","strikethrough","fontsize","fontfamily","backcolor","forecolor","superscript","subscript","insertorderedlist","insertunorderedlist","insertimage","inserttable","emotion","spechars","unlink","link"],[]]
   });
  editor.render("js_editor");

  // 初始化剩余字数
  setNum('js_title', 30);
  $('.js_title').keyup(function(){
    setNum('js_title', 30);
  });
  
  $('.js_link').blur(function(){
    var link = $(this).val();
    if (!link.match(/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]+)([\/\w \.-]*)*\/?$/)) {
      showMsg('请填写正确的链接');
      isLink = 0;
    } else {
      isLink = 1;
    }
  });

  // 提交验证
  $('.js_submit').click(function(e){
    e.preventDefault();
    var title      = $.trim($('.js_title').val());
    var link       = $.trim($('.js_link').val());
    var content    = $.trim(editor.getContent());
    if (!title) {
      showMsg('标题不能为空');
      return;
    }
    if (getFontNum(title) > 30) {
      showMsg('标题不能超过30字');
      return;
    }
    {if !$id}
      var cover = $.trim($('.js_cover').val());
      if (!cover) {
        showMsg('封面不能为空');
        return;
      }
    {/if}
    if (!isLink && link != '') {
      showMsg('请填写正确的链接');
      return;
    }

    $('.js_content').val(content);
    $('.js_creatForm').submit();
  });
  
  // 上传图片预览
  $(".js_upFile").each(function(i){
    $(this).change(function(e){
      handleFileSelect($(this));
    });
  });
});
</script>
{include_core file="admin/lib/footer.html"}